<template>
  <div class="result">
    <div class="re_input">
      <div>
        <div class="re_div">
          <img
            src="https://o6wndwjxn.qnssl.com/search.svg"
            alt=""
          >
          <input
            type="text"
            value=""
            placeholder="搜索"
            v-model="re_input"
          />
        </div>
      </div>
      <div @click="re_submit(re_search_status)">搜索</div>
    </div>
    <div class="re_tab">
      <div
        :class="re_select == 0?'re_active':''"
        @click="re_tab(0)"
      >课程</div>
      <div
        :class="re_select == 1?'re_active':''"
        @click="re_tab(1)"
      >讲师</div>
      <div
        v-show="re_tab_status"
        class="re_tab_price"
      >
        <div
          :class="re_tab_select == 0?'rt_active':''"
          @click="re_tab_tab(0)"
        >销量</div>
        <div
          :class="re_tab_select == 1?'rt_active':''"
          @click="re_tab_tab(1)"
          style="margin-left: 10px;"
        >价格
          <!-- 绿 -->
          <div
            class="re_tab_item"
            v-show="re_icon_true"
          >
            <img
              v-if="re_icon==0"
              src="https://o6wndwjxn.qnssl.com/Unchecked%20-%20on.svg"
              alt=""
            >
            <img
              v-else
              src="https://o6wndwjxn.qnssl.com/Unselected%20--%20down.svg"
              alt=""
            >
          </div>
          <!-- 灰 -->
          <div
            class="re_tab_item"
            v-show="re_icon_false"
          >
            <img
              v-if="re_icon==0"
              src="https://o6wndwjxn.qnssl.com/%E7%BA%A2-%E4%B8%8A@2x.png"
              alt=""
            >
            <img
              v-else
              src="https://o6wndwjxn.qnssl.com/%E7%BA%A2-%E4%B8%8B@2x.png"
              alt=""
            >
          </div>
        </div>
      </div>
    </div>
    <div style="height: 80px;"></div>
    <div class="re_box">
      <div
        v-if="re_select==0"
        class="re_curriculum"
      >
        <div
          class="re_box_item"
          v-for="(item,index) in re_curriculum"
          :key='index'
          @click="re_pop_click(item)"
        >
          <img
            :src="item.cover"
            alt=""
          >
          <div>
            <div class="item-title">{{item.title}}</div>
            <div class="item-count">
              <span>共{{item.count}} 课 | </span>
              <span>¥{{item.money/100}}</span>
              <span>¥{{item.preferential_money/100}}</span>
            </div>
          </div>
        </div>
        <div
          v-show="re_ke_kong"
          class="showkong"
        >
          <kong :type='re_type'></kong>
        </div>
      </div>

      <div
        v-if="re_select == 1"
        class="re_teacher"
      >
        <div
          class="re_box_user"
          v-for="(item,index) in re_teacher"
          :key='index'
          @click="re_tea_click(item.lecturer_id)"
        >
          <div>
            <img
              :src="item.img"
              alt=""
            >
          </div>
          <div class="re_user_item">
            <div>{{item.name}}</div>
            <div>{{item.label}}</div>
            <img src="https://o6wndwjxn.qnssl.com/%E7%AE%AD%E5%A4%B4@2x.png">
            <!-- <p>{{item.introduction}}</p> -->
          </div>

        </div>
        <div
          v-show="re_tea_kong"
          class="obs"
        >
          <kong :type='re_type'></kong>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import kong from '@/components/public/kong.vue'
import {
  search
} from '@/api/search'
export default {
  components: {
    kong
  },
  data () {
    return {
      re_type: '搜索内容',
      re_ke_kong: true,
      re_tea_kong: true,
      re_input: '',
      re_search_status: 0,
      re_select: 0,
      re_tab_select: 0,
      re_tab_status: true,
      re_icon_true: true,
      re_icon_false: false,
      re_icon: 0,
      re_sub_order: 1, // 搜搜条件
      re_sub_sort: 1, // 搜索排序
      re_sub_type: 'title',
      re_curriculum: [],
      re_teacher: []
    }
  },
  created () {
    this.re_input = this.$route.params.input
    if (this.$route.params.input == undefined || this.re_input == undefined) {
      // this.$router.push({
      //   name: 'co_search'
      // })
      this.$router.go(-1)
    }
    this.re_submit(0)
  },
  methods: {
    re_tea_click (e) {
      this.$router.push({
        path: '/teacher',
        query: {
          lecturer_id: e
        }
      })
    },
    re_pop_click (item) {
      console.log(item)
      if (window.__wxjs_is_wkwebview !== true) {
        if (item.is_type === 1) {
          this.$router.push({
            path: '/timelimiteddiscount',
            query: {
              discount_id: item.discount_id,
              curriculum_id: item.curriculum_id
            }
          })
          return false
        }
        if (item.is_type === 2) {
          this.$router.push({
            path: '/assembledetails',
            query: {
              join_class_id: item.assemble_id, // 拼团id
              curriculum_id: item.curriculum_id // 课程 ID
            }
          })
          return false
        }
        this.$router.push({
          path: '/coursedetails',
          query: {
            curriculumId: item.curriculum_id
          }
        })
      } else {
        if (item.is_type === 1) {
          window.location.href = `/timelimiteddiscount?&curriculum_id=${item.curriculum_id}&discount_id=${item.discount_id}`
        } else if (item.is_type === 2) {
          window.location.href = `/assembledetails?join_class_id=${item.assemble_id}&curriculum_id=${item.curriculum_id}`
        } else {
          window.location.href = `/coursedetails?curriculumId=${item.curriculum_id}`
        }
      }
    },
    re_submit (e) {
      if (this.re_input == '') return
      let requery = {
        app_id: this.$store.state.app_id,
        user_id: this.$store.state.member_id,
        content: this.re_input,
        order: this.re_sub_order,
        sort: this.re_sub_sort,
        type: this.re_sub_type
      }
      search(requery).then(res => {
        this.$store.commit('updateLoadingStatus', { isLoading: false })
        let {
          code,
          data
        } = res.data
        console.log('搜索讲师详情,search', data)
        if (code === 200) {
          for (let i = data.length - 1; i >= 0; i--) {
            if (data[i].count === 0) {
              data.splice(i, 1)
            }
          }
          if (e == 0) {
            this.re_curriculum = data
            this.$forceUpdate()
            this.re_ke_kong = false
          } else {
            this.re_teacher = data
            this.$forceUpdate()
            this.re_tea_kong = false
          }
        } else {
          if (e == 0) {
            this.re_curriculum = data
            this.re_ke_kong = true
          } else {
            this.re_teacher = data
            this.re_tea_kong = true
          }
        }
      })
    },
    re_tab (e) {
      this.re_select = e
      this.re_search_status = e
      if (e == 1) {
        this.re_tab_status = false
        this.re_sub_type = 'name'
        this.re_submit(1)
      } else {
        this.re_tab_status = true
        this.re_sub_type = 'title'
        this.re_submit(0)
      }
    },
    re_tab_tab (e) {
      this.re_tab_select = e
      if (e == 0) {
        this.re_icon_true = true
        this.re_icon_false = false
        this.re_sub_order = 1
        this.re_sub_sort = 1
        this.re_submit(0)
      } else {
        this.re_icon_true = false
        this.re_icon_false = true
        this.re_sub_order = 2
        if (this.re_tab_select == 1) {
          if (this.re_icon == 0) {
            this.re_icon = 1
            this.re_sub_sort = 1
            this.re_submit(0)
          } else {
            this.re_icon = 0
            this.re_sub_sort = 2
            this.re_submit(0)
          }
        }
        // this.re_submit()
      }
    }
  }
}
</script>

 <style scoped>
.item-title {
  font-family: PingFangSC-Medium;
  font-size: 15px;
  color: #333333;
  text-overflow: ellipsis;
  display: -webkit-box;
  /* -webkit-box-orient: vertical; */
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.showkong {
  width: 100vw;
  height: 400px;
  position: absolute;
  left: 0;
}
.re_input {
  width: 100%;
  height: 40px;
  overflow: hidden;
  display: flex;
  position: fixed;
  left: 0;
  top: 0px;
  background: white;
}

.re_div > img {
  height: 20px;
  margin: 5px;
  margin-left: 10px;
}

.re_input {
  width: 100%;
  display: flex;
  padding: 0 5%;
}

.re_input > div:first-child {
  flex: 4;
}

.re_input > div:last-child {
  flex: 1;
  text-indent: 20px;
  text-align: center;
  line-height: 40px;
  font-size: 17px;
  color: #da4131;
  padding-top: 5px;
}

.re_div {
  background: #f5f5f5;
  height: 30px;
  margin: 10px 0 5px 0;
  position: relative;
  border-radius: 30px;
}

.re_div > input {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  background: none;
  border: none;
  outline: none;
  text-indent: 40px;
  font-size: 15px;
}

.re_box {
  margin: 0 5%;
  width: 90%;
}

.re_tab {
  width: 90%;
  height: 40px;
  line-height: 40px;
  font-size: 14px;
  color: #666666;
  position: fixed;
  left: 5%;
  top: 40px;
  background: white;
}

.re_active {
  font-size: 18px;
  color: #333;
  font-weight: bold;
  line-height: 40px;
  position: relative;
}
.re_active::after {
  content: "";
  width: 50%;
  height: 3px;
  background-color: #da4131;
  position: absolute;
  bottom: 0;
  left: 50%;
  border-radius: 10px;
  transform: translate(-50%, 0);
}
.re_tab_price {
  position: absolute;
  right: 0;
  top: 0;
  height: 40px;
  line-height: 40px;
}

.rt_active {
  font-size: 14px;
  color: #da4131;
}

.re_tab_price > div {
  display: inline-block;
}

.re_tab_item {
  display: inline-block;
}

.re_tab_item > img {
  display: inline-block;
  width: 6px;
}

.re_tab > div {
  display: inline-block;
  /* margin: 0 10px; */
}

.re_tab > div:nth-child(1) {
  margin-right: 15px;
}

.re_curriculum,
.re_teacher {
  width: 100%;
}

.re_box_item {
  width: 100%;
  display: flex;
  height: 72px;
  margin-top: 22px;
}
.re_box_item:nth-child(odd) {
  margin-right: 6%;
}

.re_box_item > img {
  width: 132px;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
  flex: 0 0 132px;
  margin-right: 7px;
}

.re_box_item > div:nth-child(2) {
  flex: 1;
  position: relative;
}
.item-count {
  position: absolute;
  bottom: 0;
  font-family: PingFangSC-Regular;
}
.item-count > span:nth-child(1) {
  font-size: 11px;
  color: #999999;
}
.item-count > span:nth-child(2) {
  font-size: 11px;
  color: #999999;
  text-decoration: line-through;
}
.item-count > span:nth-child(3) {
  font-family: PingFangSC-Semibold;
  font-size: 11px;
  color: #da4131;
}
.re_box_user {
  display: flex;
  height: 50px;
  margin-top: 20px;
  align-items: center;
}

.re_box_user > div:first-child img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 2px;
  border-radius: 50%;
}

.re_box_user > div:first-child {
  flex: 0 0 40px;
  height: 40px;
  margin-right: 12px;
}
.re_user_item {
  height: 40px;
  position: relative;
  flex: 1;
}
.re_user_item > img {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translate(0, -50%);
  width: 4px;
  height: 8px;
}
.re_user_item > div:nth-child(1) {
  font-size: 15px;
  color: #333333;
}

.re_user_item > div:nth-child(2) {
  font-size: 14px;
  color: #999999;
  position: absolute;
  bottom: 0;
}

.re_user_item > p:nth-child(3) {
  font-size: 12px;
  color: #999999;
  text-overflow: ellipsis;
  display: -webkit-box;
  /* -webkit-box-orient: vertical; */
  /*! autoprefixer: off */
  -webkit-box-orient: vertical;
  /* autoprefixer: on */
  -webkit-line-clamp: 3;
  overflow: hidden;
}
</style>
